package com.joysuch.wwyt.common.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.joysuch.wwyt.common.entity.CommonBusinessNotice;
import com.joysuch.wwyt.common.service.CommonBusinessNoticeService;
import com.joysuch.wwyt.core.common.ajax.ResultBean;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author heqifeng
 * @since 2022-01-10
 */
@RestController
@RequestMapping("/common/business-notice")
@Api(tags = "消息中心")
public class CommonBusinessNoticeController {

    @Autowired
    private CommonBusinessNoticeService commonBusinessNoticeservice;


    @GetMapping("getNoticeByType")
    public ResultBean getNoticeByType(Integer index,Integer pageNo,Integer size) {
        IPage<CommonBusinessNotice> page = commonBusinessNoticeservice.getNoticeType(index, pageNo, size);
        return ResultBean.pageData(page.getRecords(),page.getTotal());
    }

    @GetMapping("getUnreadSubscript")
    public ResultBean getUnreadSubscript() {
        return ResultBean.success(commonBusinessNoticeservice.getSubscriptForUnread());
    }
    @GetMapping("getUnreadSubscriptList")
    public ResultBean getUnreadSubscriptList() {
        return ResultBean.success(commonBusinessNoticeservice.getSubscriptForUnreadList());
    }

    @GetMapping("getCountGroup")
    public ResultBean getCountGroup() {
        return ResultBean.success(commonBusinessNoticeservice.getCountByGroup());
    }

    @GetMapping("readNoticeByType")
    public ResultBean readNoticeByType(Integer index, Date sendTime) {
        return ResultBean.success(commonBusinessNoticeservice.readNoticeBatchByType(index, sendTime));
    }

    @PostMapping("deleteNoticeBatch")
    public ResultBean deleteNotice(@RequestBody List<Long> ids) {
        return ResultBean.success(commonBusinessNoticeservice.deleteNoticeBatch(ids));
    }

    @GetMapping("deleteNoticeByType")
    public ResultBean deleteNotice(Integer index) {
        return ResultBean.success(commonBusinessNoticeservice.deleteNoticeByType(index));
    }

    @GetMapping("delete-redundancy-notify")
    @ApiOperation("删除无用通知")
    public ResultBean deleteRedundancyNotify() {
        commonBusinessNoticeservice.deleteNotify();
        return ResultBean.success("");
    }

    @GetMapping("delete-redundancy-notify-by-day")
    @ApiOperation("根据天数删除无用通知")
    public ResultBean deleteRedundancyNotifyByDay(Integer day) {
        commonBusinessNoticeservice.deleteNotifyByDay(day);
        return ResultBean.success("");
    }

}

